﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Specialized;
using System.IO;

namespace Eugenhome.Atrium.Bookmark.Web
{
    /// <summary>
    /// 
    /// </summary>
    public partial class DDnsUpdate : System.Web.UI.Page
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {

            DynDNSController ddController = new DynDNSController(Server.MapPath(""), "hjas34pdoih38alerm95nebraa");

            if (ddController.Loaded)
            {
                Response.Write(string.Format("Aktuelle Daten:<br/>User: {0}<br/>Host: {1}<br/>LastUpdate: {2}<br/><br/>", ddController.User, ddController.Host, ddController.LastUpdate));
            }
            else
            {
                Response.Write("Aktuelle Daten:<br/>keine<br/><br/>");
            }

            Response.Write(string.Format("QueryString:<br/>User: {0}<br/>RemoteAddr: {1}<br/>APPL_PHYSICAL_PATH: {2}<br/><br/>", Request.QueryString["usr"], Request.ServerVariables["REMOTE_ADDR"], Server.MapPath("")));

            if (Request.QueryString["usr"] != null && !Request.QueryString["usr"].Trim().Equals(string.Empty))
            {
                try
                {
                    ddController.UpdateClientData(Request.QueryString["usr"], Request.ServerVariables["REMOTE_ADDR"]);
                }
                catch (Exception ex)
                {
                    Response.Write("Fehler:<br/>" + ex.Message + "<br/><br/>");
                }

                if (ddController.Loaded)
                {
                    Response.Write(string.Format("Neue Daten:<br/>User: {0}<br/>Host: {1}<br/>LastUpdate: {2}<br/><br/>", ddController.User, ddController.Host, ddController.LastUpdate));
                }
                else
                {
                    Response.Write("Neue Daten:<br/>keine<br/><br/>");
                }

                //Dictionary<string, string> queryString = new Dictionary<string, string>();
                //foreach (string key in Request.QueryString.AllKeys)
                //{
                //    queryString.Add(key, Request.QueryString[key]);
                //}
                //Dictionary<string, string> serverVariables = new Dictionary<string, string>();
                //foreach (string key in Request.QueryString.AllKeys)
                //{
                //    if (Request.ServerVariables[key].Trim().Length > 0)
                //        serverVariables.Add(key, Request.ServerVariables[key]);
                //}

                //ddController.UpdateRequestData(queryString, serverVariables);
            }
        }
    }
}